/*
 * Copyright (c) 2018. J4dream Created.
 */

package com.j4dream.property.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.Bindable;
import org.springframework.boot.context.properties.bind.Binder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;


@Configuration
public class PropertiesConfig {

    @Autowired
    private Environment environment;

    @Bean
    public EmailConfig emailConfig() {
        return Binder
                .get(environment)
                .bind("app.email.service", Bindable.of(EmailConfig.class))
                .orElseThrow(IllegalStateException::new);
    }

    @Data
    public static class EmailConfig {
        private String activeUrl;
        private String resetPassUrl;
        private String sender;
    }
}
